package com.ease.web.server;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ease.common.util.Detect;
import com.ease.common.util.ServerDetector;
import com.ease.common.vo.Endpoint;

public abstract class ServerEndpointDetector extends Detect {

	private static final transient Log log = LogFactory.getLog(ServerEndpointDetector.class);

	public abstract Endpoint get(String protocol, String scheme);

	private static Endpoint serverEndpoint;

	// server type
	// public static getServerType() {
	//
	// }

	public static Endpoint getServerEndpoint() {
		if (null == serverEndpoint) {// TODO singleton needed?
			String protocol = "HTTP/1.1";
			String scheme = "http";
			ServerEndpointDetector serverEndpointDetector = null;
			if (ServerDetector.isJBoss()) {
				try {
					serverEndpointDetector = (ServerEndpointDetector) Class.forName("com.ease.web.server.JbossEndpointDetector").newInstance();
				} catch (Exception e) {
					log.error("protocol=" + protocol + ",scheme=" + scheme, e);
				}
			}
			if (null != serverEndpointDetector) {
				serverEndpoint = serverEndpointDetector.get(protocol, scheme);
			} else {
				log.debug("serverEndpointDetector not found, protocol=" + protocol + ",scheme=" + scheme);
			}
		}
		return serverEndpoint;
	}

}
